home *** CD-ROM | disk | FTP | other *** search
- /*--------------------------------------------------------------------------*/
- /* The Opus Computer-Based Conversation System */
- /* (c) Copyright 1987, Wynn Wagner III, All Rights Reserved */
- /* */
- /* YOOHOO is a trademark of Wynn Wagner III */
- /* */
- /* YOOHOO-YOOHOO/2U2 is */
- /* Copyright 1987, Wynn Wagner III, All Rights Reserved */
- /* */
- /* This module was written by Bob Hartman */
- /* */
- /* */
- /* BinkleyTerm SEAdog Mail Session Routines */
- /* */
- /* */
- /* This module is a very simple FOSSIL-based terminal emulator. It is */
- /* provided for your information only. You will find routines that need */
- /* to be coded and identifiers to be resolved. It has been previously */
- /* known as "OpusLink" and "OConnect". The use of the name "BinkleyTerm" */
- /* does not preclude the possibility that another "OpusLink" or "OConnect" */
- /* could be released. */
- /* */
- /* There is absolutely no guarantee that anything here will work. If you */
- /* break this routine, you own both pieces. */
- /* */
- /* USAGE: You may use this material in any program with no obligation */
- /* as long as there is no charge for your program. For more */
- /* information about commercial use, contact the "OPUSinfo HERE" */
- /* BBS (124/111). */
- /* */
- /* */
- /*--------------------------------------------------------------------------*/
-
- #include <signal.h>
- #include <ctype.h>
- #include <conio.h>
- #include <time.h>
-
- #define WAZOO_SECTION
- #define MATRIX_SECTION
-
- #define MYPRODUCT 0x0f
-
- #include "zmodem.h"
- #include "com.h"
- #define rb_plus "rb+"
-
- extern char *BUNDLE_msg;
- extern char *FIND_msg;
- extern char *WRITE_msg;
- extern char *FLAGGING_msg;
- extern char *TRUNC_msg;
-
- extern char *ext_flags; /* Change to whatever, and */
- extern int net_problems; /* This should be external */
- extern char no_pickup;
- extern int remote_net, remote_node;
- extern int called_net, called_node;
- extern char *remote_password;
- extern char no_requests;
- extern int n_requests;
- extern long timezone;
-
- SEA_sendreq ()
- {
- char fname[80];
- char reqf[80];
- char *p, *name, *pw;
- int i, j, done, done1, nfiles;
- unsigned int crc;
- FILE *fp;
- long t1, timerset();
-
-
- t1 = timerset (1000);
-
- sprintf( fname,
- "%s%04x%04x.REQ",
- ctl.hold_area,called_net,called_node);
- errno = 0;
-
- /* If we have file requests, then do them */
- if (stat(fname,reqf))
- {
- status_line (":No outgoing file requests");
- }
- else
- {
- status_line (":Outbound file requests");
- /* Open the .REQ file */
- if ((fp = fopen (fname, "r")) == NULL)
- {
- SENDBYTE(ETB);
- return (1);
- }
-
- /* As long as we do not have EOF, read the request */
- while ((fgets (reqf, 79, fp) != NULL) && (CARRIER))
- {
- /* Properly format the request */
-
- /* First get rid of the trailing junk */
- p = reqf+strlen(reqf)-1;
- while ((p>=reqf)&&(isspace(*p)))
- *p-- = '\0';
-
- /* Now get rid of the beginning junk */
- p = reqf;
- while ((*p) && (isspace (*p)))
- p++;
- /* This is where the name starts */
- name = p;
-
- /* If the first char is ; then ignore the line */
- if (*name == ';')
- continue;
-
- /* Now get to where the name ends */
- while ((*p) && (!isspace (*p)))
- p++;
- if (*p)
- {
- *p = '\0';
- ++p;
- while ((*p) && (*p != '!'))
- p++;
- if (*p == '!')
- {
- *p = ' ';
- }
- pw = p;
- }
- else
- {
- pw = p;
- }
-
- if (req_out (name, pw))
- continue;
-
- /* Wait for ACK or ENQ */
- t1 = timerset (1000);
- done = 0;
- while ((!timeup (t1)) && CARRIER && !done)
- {
- j = TIMED_READ(0);
- if (j >= 0)
- {
- if (j == ACK)
- {
- /* If ACK, receive files using SEAlink */
- nfiles = 0;
- done1 = 0;
- do
- {
- if ((i = try_sealink ()) == 0)
- {
- if (!recvmdm7 (reqf))
- {
- done1 = 1;
- }
- else
- {
- if (!receive_file (ctl.filepath, NULL, 'T'))
- {
- if (locate_y>1) gotoxy(0,locate_y-1);
- done1 = 1;
- }
- else
- ++nfiles;
- }
- }
- else if (i == 1)
- {
- if (!receive_file (ctl.filepath, NULL, 'F'))
- {
- if (locate_y>1) gotoxy(0,locate_y-1);
- done1 = 1;
- }
- else
- ++nfiles;
- }
- else
- {
- done1 = 1;
- }
-
- } while (CARRIER && !done1);
-
- status_line (":Received %d files", nfiles);
- done = 1;
- t1 = timerset (1000);
-
- /* wait for request start */
- while ((TIMED_READ(0) != ENQ) && (!timeup (t1)) && CARRIER)
- time_release();
- }
- else if (j == ENQ)
- {
- /* If ENQ, report no files received */
- req_out (name, pw);
- }
- else
- {
- time_release();
- }
- }
- }
- }
- fclose (fp);
- unlink (fname);
- status_line (":End of outbound file requests");
- }
-
- /* Finish the file requests off */
- SENDBYTE(ETB);
- }
-
- SEA_recvreq ()
- {
- int done;
- int i, j;
- int recno;
- int retval;
- int nfiles;
- int nfiles1;
- char p;
- char *ptr;
- char reqs[64];
- char req[64];
- long t1, timerset();
- char *n_frproc();
-
- t1 = timerset (2000);
-
- if (no_requests)
- {
- /* Refuse file requests */
- SENDBYTE(CAN);
- status_line ("*Refusing inbound file requests");
- return TRUE;
- }
-
- /* Try the bark stuff */
- done = 0;
- nfiles = 0;
- status_line (":Inbound file requests");
- while (CARRIER && !done && (!timeup (t1)))
- {
- /* Send out the start signal */
- SENDBYTE(ENQ);
-
- /* Wait for the response */
- j = TIMED_READ(2);
-
- switch (j)
- {
- case ACK:
- recno = -1;
- nfiles1 = 0;
- if ((retval = get_req_str (reqs, req, &recno)) > 0)
- {
- SENDBYTE(ACK);
- do
- {
- if (reqs[0])
- i = xfermdm7 (reqs);
- else
- i = 2;
-
- p = 'T';
- if (i == 0)
- {
- net_problems = 1;
- continue;
- }
- else if (i == 2)
- p = 'F';
-
- if (retval == 1)
- {
- send_file (reqs, p);
- ++nfiles;
- ++nfiles1;
- }
- if (nfiles > n_requests)
- {
- status_line ("!File Request limit exceeded");
- recno = -1;
- }
- else if (gen_req_name (reqs, req, &recno) == 2)
- {
- recno = -1;
- }
- } while (CARRIER && (recno >= 0));
-
- if (retval != 1)
- {
- send_file (NULL, 'S');
- }
- status_line (":%d matching files sent", nfiles1);
- }
- t1 = timerset (2000);
- break;
-
- case ETB:
- case ENQ:
- done = 1;
- break;
-
- case 'C':
- case NAK:
- SENDBYTE(EOT);
- CLEAR_INBOUND();
- break;
- }
- }
- status_line (":End of inbound file requests");
- return TRUE;
- }
-
- try_sealink ()
- {
- int i, j;
- long t1, timerset();
-
- for (i = 0; i < 5; i++)
- {
- SENDBYTE ('C');
-
- t1 = timerset (100);
- while (!timeup (t1) && CARRIER)
- {
- if ((j = PEEKBYTE()) >= 0)
- {
- if (j == SOH)
- return (1);
- j = TIMED_READ(0);
- if (j == EOT)
- return (2);
- else if (j == TSYNC)
- return (0);
- }
- else
- {
- time_release();
- }
- }
-
- if (!CARRIER)
- break;
- }
-
- return (0);
- }
-
- req_out (name, pw)
- char *name, *pw;
- {
- char *p;
- char buf[80];
- unsigned int crc;
-
- /* send the request */
- p = name;
- if (!*p)
- return (1);
-
- status_line ("*Requesting '%s' %s%s", name, (*pw)?"with password":"", pw);
- SENDBYTE(ACK);
- crc = 0;
- while (*p)
- {
- SENDBYTE(*p);
- crc = xcrc(crc,(byte )(*p));
- ++p;
- }
-
- /* This is for straight requests being the standard */
- SENDBYTE(' ');
- crc = xcrc(crc,(byte )(' '));
- SENDBYTE('0');
- crc = xcrc(crc,(byte )('0'));
- p = pw;
- while (*p)
- {
- SENDBYTE(*p);
- crc = xcrc(crc,(byte )(*p));
- ++p;
- }
-
- SENDBYTE(ETX);
- crc = crc_finish(crc);
- SENDBYTE( crc&0xff );
- SENDBYTE( crc>>8 );
- return (0);
- }
-
- get_req_str (reqs, req, recno)
- char *reqs, *req;
- int *recno;
- {
- unsigned int crc, crc1, crc2, crc3;
- int i,j;
-
- crc = i = 0;
- while (CARRIER)
- {
- j = TIMED_READ(2);
- if (j < 0)
- return (0);
-
- if (j == ETX)
- {
- crc1 = TIMED_READ(2);
- crc2 = TIMED_READ(2);
- crc3 = (crc2<<8)+crc1;
- if (crc3 != crc)
- {
- status_line("!Bad crc - trying again");
- return (0);
- }
- req[i] = '\0';
- return (gen_req_name (reqs, req, recno));
- }
- else
- {
- req[i++] = j&0xff;
- crc = xcrc (crc,j&0xff);
- }
- }
- return (0);
- }
-
- gen_req_name (reqs, req, recno)
- char *reqs, *req;
- int *recno;
- {
- char *q, *q1;
- struct stat st;
- extern char *n_frproc();
- char buf[32];
- byte *rqname;
- long fsecs, atol();
- int save_rec;
-
- save_rec = *recno;
- q = req;
- q1 = buf;
- /* Get the filename */
- while ((*q) && (!isspace(*q)))
- {
- *q1++ = *q++;
- }
-
- /* If we have more characters, go on */
- if (*q)
- {
- /* Skip the space */
- ++q;
-
- fsecs = atol (q);
-
- /* Skip the digits */
- while ((*q) && isdigit (*q))
- ++q;
-
- /* If we have more, get the password */
- if (*q)
- {
- /* Skip the space */
- ++q;
-
- *q1++ = ' ';
- *q1++ = '!';
- while (*q)
- {
- *q1++ = *q++;
- }
- *q1++ = '\0';
- }
- }
-
- for (;;)
- {
- if ((rqname = n_frproc(buf, recno, (fsecs == 0)?0:1 )) != NULL)
- {
- /* If this is an update request, then check it out */
- if (!stat (rqname, &st))
- {
- if (st.st_atime - timezone <= fsecs)
- {
- continue;
- }
- }
- strcpy (reqs, rqname);
- return (1);
- }
- else
- {
- q = buf;
- while ((*q) && !isspace (*q))
- ++q;
- *q = '\0';
- if (save_rec == -1)
- status_line("!No files matched '%s'", buf);
- reqs[0] = '\0';
- return (2);
- }
- }
- }
-